Skip to content

Sync: Introduce CPT and helper for Activity Log entries#48567

Merged
coder-karen merged 20 commits into
trunkfrom
add/sync-custom-post-types-for-activity-log
May 11, 2026
Merged

Sync: Introduce CPT and helper for Activity Log entries#48567
coder-karen merged 20 commits into
trunkfrom
add/sync-custom-post-types-for-activity-log

Conversation

@coder-karen
Copy link
Copy Markdown
Contributor

@coder-karen coder-karen commented May 6, 2026

Fixes ACTLOG-57
Requires 215994-ghe-Automattic/wpcom to be deployed first to prevent WPcom test failures.

Proposed changes

Adds a Jetpack Sync helper class for creating custom customer-visible Activity Log entries.

  • Introduce Automattic\Jetpack\Sync\Activity_Log_Event as the API for creating custom Activity Log events.
  • Register a non-public jp_act_log_event CPT for transporting custom Activity Log event payloads through Sync.
  • Store the event payload as JSON in post_content.
  • Validate and sanitize event input:
    • required title and content
    • optional source
    • optional severity limited to info, success, warning, or error
  • Normalize REST create requests like { title, content, source, severity } into the canonical JSON payload.
  • Restrict REST access to trusted/admin contexts and block edit/delete-style CPT operations.
  • Route valid custom event posts through the existing jetpack_published_post Sync pipeline.
  • Allow normal save/delete Sync actions for jp_act_log_event posts so remote/cache DB state stays consistent.
  • Reuse the custom event payload validation for direct jp_act_log_event inserts so invalid severity values, empty sanitized content, and malformed payloads are not enqueued through jetpack_published_post.
  • Prevent Activity Log event posts from being publicized or included in Jetpack sitemaps.
  • Add Sync package tests for validation, sanitization, CPT creation, and enqueue behavior.

Related product discussion/links

  • This is part of an RSM project to add custom entries to the Activity Log. See Linear link above for more.

  • Requires the matching WPcom Activity Log handling in 215249-ghe-Automattic/wpcom, which translates valid jp_act_log_event posts into custom_event__created entries and prevents malformed payloads from falling through as generic post publish events.

Does this pull request change what data or activity we track or use?

No.

Testing instructions

To test, apply this PR on a test site using the Jetpack Beta tester plugin, for the Jetpack plugin (or apply the PR if testing locally).

  • Using a code snippets plugin, add the following snippet: 3b2d3-pb
  • Visit yoursite.com/wp-admin/?test_activity_log=1
  • You may want to log the args on the WPcom end to confirm they're received and with the right content, eg. under case 'jetpack_published_post': in Jetpack_Sync_Server_Replicator
  • Alternatively, apply 215249-ghe-Automattic/wpcom, and ensure your Jetpack site is API sandboxed. Then, follow the same steps as above, and you should be able to view the Activity Log entries

To test the endpoint via WPcom:

  • With 215249-ghe-Automattic/wpcom applied as well as this PR for a Jetpack API sandboxed site, open up wpsh and run the following:
$blog_id = YOURBLOGID;
$rest_url = sprintf( '%s/?rest_route=%s', Jetpack_Data::get_client( $blog_id )->siteurl, '/wp/v2/activity-log-events' );
$response = Jetpack_Client::remote_request( [ 'url' => esc_url_raw( $rest_url ), 'blog_id' => $blog_id, 'user_id' => (int) wpcom_get_blog_owner( $blog_id ), 'method' => 'POST', 'timeout' => 30, 'headers' => [ 'Content-Type' => 'application/json' ] ], wp_json_encode( [ 'title' => 'wpsh option-2 test', 'content' => 'Hello from wp/v2.', 'severity' => 'info', 'source' => 'mc'] ) );

You can run the following in wpsh to confirm a response, or wait for the entry to show on the AL:

echo wp_remote_retrieve_body( $response );

To confirm that unauthenticated rrequests are not allowed, run the same test but remove the user_id. You should get an invalid_user_permission_activity_log_event 401 response.

For Simple sites, testing via the Developer API console may be easier here:

Screenshot 2026-05-08 at 14 41 39

@coder-karen coder-karen self-assigned this May 6, 2026
@github-actions github-actions Bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: June 2, 2026
    • Code freeze: June 1, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the add/sync-custom-post-types-for-activity-log branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/sync-custom-post-types-for-activity-log
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/sync-custom-post-types-for-activity-log

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 6, 2026

Code Coverage Summary

Coverage changed in 6 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php 2/359 (0.56%) -0.00% 3 ❤️‍🩹
projects/packages/sync/src/class-main.php 15/35 (42.86%) 1.68% 0 💚
projects/packages/sync/src/class-actions.php 179/436 (41.06%) 0.23% -1 💚
projects/packages/sync/src/class-listener.php 33/200 (16.50%) 0.50% -1 💚
projects/packages/sync/src/class-settings.php 68/168 (40.48%) 1.79% -3 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/sync/src/class-activity-log-event.php 175/198 (88.38%) 💚

Full summary · PHP report · JS report

@github-actions github-actions Bot added [Plugin] Automattic For Agencies Client [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcloud Sso [Plugin] Wpcomsh labels May 6, 2026
@coder-karen coder-karen marked this pull request as ready for review May 6, 2026 15:58
@coder-karen coder-karen requested a review from a team as a code owner May 6, 2026 15:58
@coder-karen coder-karen removed the request for review from a team May 6, 2026 15:58
@coder-karen coder-karen added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels May 8, 2026
/**
* Testing the core REST CPT endpoint creates and normalizes a custom Activity Log event.
*/
public function test_core_rest_activity_log_event_endpoint_creates_event() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that these are not really testing REST_Endpoints anymore, they’re testing a core REST route registered by the CPT. But for this PR, I've kept them here because this file already sets up a REST server and dispatches requests.

@coder-karen coder-karen changed the title Sync: Introduce helper function and CPT for Activity Log entries Sync: Introduce CPT and helper for Activity Log entries May 8, 2026
Comment thread projects/packages/sync/src/class-activity-log-event.php Outdated
Comment thread projects/packages/sync/src/class-main.php
@github-actions github-actions Bot added the [Package] Jetpack mu wpcom WordPress.com Features label May 8, 2026
Copy link
Copy Markdown
Contributor

@fgiannar fgiannar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work overall!

Left a few comments mainly around performance concerns but also a bug on WPCOM with the route check logic

Comment thread projects/packages/sync/src/class-activity-log-event.php
Comment thread projects/packages/sync/src/class-activity-log-event.php Outdated
Comment thread projects/packages/sync/src/class-activity-log-event.php Outdated
Comment thread projects/packages/sync/src/class-activity-log-event.php Outdated
@coder-karen coder-karen force-pushed the add/sync-custom-post-types-for-activity-log branch from cf3ef5b to e9c8b1c Compare May 8, 2026 15:42
Copy link
Copy Markdown
Contributor

@fgiannar fgiannar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

Tested with a self-hosted and Simple site via the Dev console and everything works as expected 👍

Thanks for the unit test coverage too 👍

@coder-karen coder-karen added DO NOT MERGE don't merge it! and removed [Status] Needs Review This PR is ready for review. labels May 11, 2026
@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 11, 2026
@coder-karen coder-karen added [Status] Blocked / Hold and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels May 11, 2026
@coder-karen coder-karen added [Status] Ready to Merge Go ahead, you can push that green button! and removed DO NOT MERGE don't merge it! [Status] Blocked / Hold labels May 11, 2026
@coder-karen coder-karen merged commit 5bf5966 into trunk May 11, 2026
123 of 124 checks passed
@coder-karen coder-karen deleted the add/sync-custom-post-types-for-activity-log branch May 11, 2026 08:36
@github-actions github-actions Bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label May 11, 2026
@github-actions github-actions Bot added this to the jetpack/15.9 milestone May 11, 2026
@github-actions github-actions Bot added the [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Jetpack mu wpcom WordPress.com Features [Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants